#!/home/luyanfei/.local/bin/checkio --domain=py run speechmodule

# https://py.checkio.org/mission/speechmodule/

# Stephen's speech module is broken.    This module is responsible for his number pronunciation.    He has to click to input all of the numerical digits in a figure,    so when there are big numbers it can take him a long time.    Help the robot to speak properly and increase his number processing speed by writing a new speech module for him.    All the words in the string must be separated by exactly one space character.    Be careful with spaces -- it's hard to see if you place two spaces instead one.
# 
# Input:A number as an integer.
# 
# Output:The string representation of the number as a string.
# 
# How it is used:This concept may be useful for the speech synthesis software or automatic reports systems.    This system can also be used when writing a chatbot by assigning words or phrases numerical    values and having a system retrieve responses based on those values.
# 
# Precondition:0 < number < 1000
# 
# 
# END_DESC

wton = dict(
    one = 1, two = 2, three = 3, four = 4, five = 5,
    six = 6, seven = 7, eight = 8, nine = 9, ten = 10,
    eleven = 11, twelve = 12, thirteen = 13, fourteen = 14, fifteen = 15,
    sixteen = 16, seventeen = 17, eighteen = 18, nineteen = 19, twenty = 20,
    thirty = 30, forty = 40, fifty = 50, sixty = 60, seventy = 70,
    eighty = 80, ninety = 90, hundred = 100
)

ntow = {num: name for name, num in wton.items()}

def checkio(number):
    result = ''
    remainder = number % 100
    quotient = int(number / 100)
    if(remainder == 0 and quotient > 0):
        return ntow[quotient] + ' hundred'
    if(quotient > 0):
        result += ntow[quotient] + ' hundred '
    if(ntow.get(remainder)):
        result += ntow[remainder]
    else:
        result += ntow[int(remainder / 10) * 10]
        remainder2 = remainder % 10
        if(remainder2 > 0):
            result += ' ' + ntow[remainder2]
    return result

if __name__ == '__main__':
    assert checkio(4) == 'four', "First"
    assert checkio(133) == 'one hundred thirty three', "Second"
    assert checkio(12)=='twelve', "Third"
    assert checkio(101)=='one hundred one', "Fifth"
    assert checkio(212)=="two hundred twelve", "Sixth"
    assert checkio(40)=='forty', "Seventh, forty - it is correct"
    print('All ok')
